<!DOCTYPE html>
<html>
<head>
    <style>
        textarea {
            width: 100%;
            height: 20em;
        }
    </style>
    <script>
    var worker = new Worker('r-worker.js');

    worker.onerror = function () {
        console.error("WORKER ERROR", arguments);
    };

    worker.onmessage = function(evt) {
        var data = JSON.parse(evt.data),
            buildText = data.buildText,
            out = data.out;

        document.getElementById('output').value = out;
        document.getElementById('buildMessages').value = buildText;
    };

    document.addEventListener('DOMContentLoaded', function (evt) {
        document.getElementById('build').addEventListener('click', function (evt) {
            worker.postMessage('run');
        }, false);
    }, false);
    </script>
</head>
<body>
    <h1>r.js in the browser</h1>


    <p>A test of running r.js in the browser.</p>

    <p>
        <button id="build">Build it</button>
    </p>

    <h2>Build Messages</h2>
    <textarea id="buildMessages"></textarea>

    <h2>Output</h2>
    <textarea id="output"></textarea>
</body>
</html>